home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Toolbox / Live Scroll 1.0 / Sources / Utilities.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-13  |  2.9 KB  |  167 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Utitlities.c
  3.  
  4.     Contains:    General utility routines
  5.  
  6.     Written by:    Chris White, Developer Technical Support
  7.     
  8.     Copyright:    © 1996 by Apple Computer, Inc., all rights reserved.
  9.     
  10.     Change History (most recent first):
  11.     
  12.             03/29/96            CW        First release
  13.  
  14. */
  15.  
  16.  
  17. #pragma segment Core
  18.  
  19.  
  20.  
  21. // System Includes
  22.  
  23. #ifndef __TYPES__
  24.     #include <Types.h>
  25. #endif
  26.  
  27. #ifndef __TEXTUTILS__
  28.     #include <TextUtils.h>
  29. #endif
  30.  
  31. #ifndef __DIALOGS__
  32.     #include <Dialogs.h>
  33. #endif
  34.  
  35.  
  36. #ifndef __CODEFRAGMENTS__
  37.     #include <CodeFragments.h>
  38. #endif
  39.  
  40.  
  41. // Application Includes
  42.  
  43. #ifndef __BAREBONES__
  44.     #include "BareBones.h"
  45. #endif
  46.  
  47. #ifndef __PROTOTYPES__
  48.     #include "Prototypes.h"
  49. #endif
  50.  
  51.  
  52.  
  53.  
  54.  
  55. StringPtr CopyPStr ( Str255    inSourceStr, StringPtr outDestStr, SInt16 inDestSize )
  56. {
  57.     SInt8 dataLen = inSourceStr[0] + 1;
  58.     
  59.     if ( dataLen > inDestSize )
  60.         dataLen = inDestSize;
  61.     BlockMoveData ( inSourceStr, outDestStr, dataLen );
  62.     outDestStr[0] = dataLen - 1;
  63.     
  64.     return outDestStr;
  65. }
  66.  
  67.  
  68.  
  69. StringPtr ConcatPStr ( Str255 ioFirstStr, Str255 inSecondStr, SInt16 inDestSize )
  70. {
  71.     SInt8 charsToCopy = inSecondStr[0];
  72.     
  73.     if ( ioFirstStr[0] + charsToCopy > inDestSize - 1 )
  74.         charsToCopy = inDestSize - 1 - ioFirstStr[0];
  75.     BlockMoveData ( inSecondStr + 1,  ioFirstStr + ioFirstStr[0] + 1, charsToCopy );
  76.     ioFirstStr[0] += charsToCopy;
  77.     
  78.     return ioFirstStr;
  79. }
  80.  
  81.  
  82.  
  83. void OSTypeToPStr ( OSType inOSType, StringPtr outString )
  84. {
  85.     BlockMoveData ( &inOSType, outString + 1, sizeof ( OSType ) );
  86.     outString[0] = sizeof ( OSType );
  87.  
  88.     return;
  89. }
  90.  
  91.  
  92.  
  93. void PStrToOSType ( StringPtr inString, OSType* outOSType )
  94. {
  95.     BlockMoveData ( inString + 1, outOSType, sizeof ( OSType ) );
  96.  
  97.     return;
  98. }
  99.  
  100.  
  101.  
  102. //
  103. // Tell the user that something went wrong
  104. //
  105. void AlertUser ( SInt16 messageCode, SInt16 errorNum, StringPtr theString )
  106. {
  107.     Str255        messageString;
  108.     Str255        numberString;
  109.     
  110.     if ( messageCode > 0 )
  111.         GetIndString ( messageString, kErrorStrings, messageCode );
  112.     else
  113.         messageString[0] = '\0';
  114.      
  115.     if ( errorNum != 0 )
  116.         NumToString ( errorNum, numberString );
  117.     else
  118.         numberString[0] = '\0';
  119.      
  120.     ParamText ( messageString, numberString, theString, (StringPtr) "\p" );
  121.     
  122.     StopAlert ( kErrorDialog, nil );
  123.     
  124.     // We need to clear the param text so it isn't used by mistake
  125.     ParamText ( (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p" );
  126.     
  127.     return;
  128. }
  129.  
  130.  
  131.  
  132. void LocalToGlobalRect ( Rect* theRect )
  133. {
  134.     LocalToGlobal ( (Point*) &theRect->top );
  135.     LocalToGlobal ( (Point*) &theRect->bottom );
  136.     
  137.     return;
  138. }
  139.  
  140.  
  141.  
  142. Boolean IsMovableModal ( WindowRef theWindow )
  143. {
  144.     return (GetWVariant ( theWindow ) == movableDBoxProc);
  145. }
  146.  
  147.  
  148.  
  149. #if DEBUGGING
  150. void DebugStrNum ( Str255 str, SInt32 num )
  151. {
  152.     Str255 debug_str, tmp_str;
  153.     
  154.     BlockMoveData ( &str[0], &debug_str[0], str[0] + 1 );
  155.     
  156.     NumToString ( num , &tmp_str[0] );
  157.     debug_str[debug_str[0] + 1] = ' ';
  158.     BlockMoveData ( &tmp_str[1], &debug_str[debug_str[0] + 2], tmp_str[0] );
  159.     debug_str[0] = debug_str[0] + tmp_str[0] + 1;
  160.     DebugStr ( debug_str );
  161.     
  162.     return;
  163. }
  164. #endif
  165.  
  166.  
  167.